#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<functional>
#include<numeric>
using namespace std;

class Solution {
public:
    int numRabbits(vector<int>& answers) {
        //动态规划题目
        if(answers.empty()){
            return 0;
        }
        sort(answers.begin(),answers.end());
        vector<int> dp(answers.size(),0);
        dp[0] = answers[0]+1;
        int sum=1;
        for(int i = 1;i<answers.size();++i){
            if(answers[i]==answers[i-1]){
                ++sum;
                if(sum<=dp[i-1]){
                    dp[i] = dp[i-1];
                    dp[i-1] = 0;
                }
                else{
                    dp[i] = answers[i]+1;
                    sum=1;
                }
            }
            else {
                dp[i] = answers[i]+1;
                sum=1;
            }
        }
        return accumulate(dp.begin(),dp.end(),0);
    }
};


int main(){
    Solution S;
    vector<int> answer = {};
    cout<<S.numRabbits(answer)<<endl;
}

